package com.yang.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ModelAndViewTest {

    @RequestMapping("/mav/t1")
    public ModelAndView test1(){
        //返回一个模型视图对象
        ModelAndView mv = new ModelAndView();
        mv.addObject("msg","ControllerTest1");
        mv.setViewName("test");
        return mv;
    }

    @RequestMapping("/mav/t2")
    public String test2(Model model){
        //封装要显示到视图中的数据
        //相当于req.setAttribute("name",name);
        model.addAttribute("msg","ywq");
        return "test";
    }

    @RequestMapping("/mav/t3")
    public String test3(ModelMap modelMap){
        //封装要显示到视图中的数据
        //相当于req.setAttribute("name",name);
        modelMap.addAttribute("msg","ywq");
        return "test";
    }
}
